package com.fulong.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fulong.web.webconfig.UserStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fulong.entity.UserBaiseInfoEntity;
import com.fulong.service.UserBaiseInfoService;
import com.fulong.common.utils.PageUtils;
import com.fulong.common.utils.R;



/**
 * 
 *
 * @author fulong
 * @email ${email}
 * @date 2022-03-24 10:31:23
 */
@RestController
@RequestMapping("/userbaiseinfo")
public class UserBaiseInfoController {
    @Autowired
    private UserBaiseInfoService userBaiseInfoService;

    /**
    *
    */
    @RequestMapping("/getapproverinfo")
    public R getApproverInfo(@RequestBody Map<String, Object> params){
        return R.ok().put("label", userBaiseInfoService.getapprover(params).get("label"));
    }

    @RequestMapping("/getapproverlist")
    public R getApproverList(@RequestBody Map<String, Object> params){
        List<UserBaiseInfoEntity> list = userBaiseInfoService.list(new QueryWrapper<UserBaiseInfoEntity>().eq("role", params.get("role")));
        return R.ok().put("list" , list);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userBaiseInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		UserBaiseInfoEntity userBaiseInfo = userBaiseInfoService.getById(id);

        return R.ok().put("userBaiseInfo", userBaiseInfo);
    }


    @RequestMapping("getcurrentuserinfo")
    public R currUserinfo(){
        return R.ok().put("user", userBaiseInfoService.getById(UserStatus.getParam().getId()));
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserBaiseInfoEntity userBaiseInfo){
		userBaiseInfoService.save(userBaiseInfo);

        return R.ok().put("id" , userBaiseInfo.getId());
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserBaiseInfoEntity userBaiseInfo){
		userBaiseInfoService.updateById(userBaiseInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		userBaiseInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
